
State machine example for controlling a Brushless DC motor
==========================================================


Note: it is outside of the scope of this manual to describe the theory of operation of the brushless dc motor, 
for more details you might refer to application note AN10898 - BLDC motor control with LPC1700

The location of the motor is assumed to be determined by 3 Hall sensors, the inputs of which are called H1, H2, H3. 
These sensor inputs are used to make the SCT state machine evolve through the different states being defined, which 
are tightly related to a specific sector of operation (L_ENTRY, sect1 to sect5)

Each sector (position) of the motor is related to a specific configuration of the hall sensor values. For 3 sensors, 
there are six possible sectors the motor can be located into, each defining an angle of 60 degrees (where of course 
a full rotation is done at every 360 degrees). 

The PWM signal for a specific set of phases / switches, indicated by SW1 to SW6, is repeatedly generated within each 
state (sector), when the respective match signal happens (match1 to match6). Each phase is potentially configurable 
with a different PWM period, although they are all by default pre-initialized to use the same value (match1_val).

When the hall configuration changes, meaning a different sector (position) of the motor has been reached while rotating, 
the SCT will jump to the next state.

Note the SCT is configured in bidirectional mode in this example, which means the events which set a specific output during 
the up-counting phase will clear the same output when the same match value is reached during the down-counting phase.  

The duration of each PWM half period is determined by the period_middle match value, which limits the timer and makes it 
start counting down.

There is also an ABORT input which will trap the SCT in an error state, keeping all outputs (switches) deactivated. 
This event might happen at any time, thus is configured as being in the L_ALWAYS pseudo state.

The state machine in question will make the motor turn in a specific direction (lets say clockwise). For the opposite 
direction, a complementary setup is provided in the project.

The different hall sensor inputs have been simulated within the application by means of GPIO signals, which follow the 
same signal sequence as real world sensors. This is the current configuration provided in the main application, 
although it has been tested also successfully with a real motor. 